<template>
	<div class="container">
		<view class="head-bg">
			
		</view>
		<div class="login-container box">
			<div class="title">数字农业管理平台</div>
			<div class="login-form">
				<div class="username">
					<input v-model="loginForm.username" class="uni-input" placeholder-style="color:#F76260" placeholder="请输入账号" />
				</div>
				<div class="password">
					<input v-if="isPssword" v-model="loginForm.password" class="uni-input" placeholder-style="color:#A1A3A5" type="password" placeholder="请输入密码" />
					<input v-else v-model="loginForm.password" class="uni-input" placeholder-style="color:#A1A3A5" type="text" placeholder="请输入密码" />
					<image @click="isPssword = !isPssword" :src="$getImageSrc('eye-open.png')" class="eye-open" v-if="isPssword"></image>
					<image @click="isPssword = !isPssword" :src="$getImageSrc('eye-close.png')" class="eye-open" v-else></image>
				</div>
			</div>
			<div class="login-btn" @click="toHome">登录</div>
			<view class="identify" @click="goIdentify">虫情识别</view>
		</div>
		
	</div>
</template>

<script>
	import {
		Login 
	} from '../../untils/api.js'
	import {setStorageSync} from '../../untils/pubic.js'
	export default {
		data() {
			return {
				isPssword:true,
				loginForm:{
					username:'',  // 潼南项目  扬州监测点
					password:''  // zy@123456
				}
			}
		},
		methods: {
			toHome() {
				if(!this.loginForm.username) return uni.showToast({
					title:'请填写账号',
					icon:'none'
				})
				if(!this.loginForm.password) return uni.showToast({
					title:'请填写密码',
					icon:'none'
				})
				// getTenantId().then(res => {
				// 	console.log(res,'resss');
				// })
				// uni.showToast({
				// 	title:'登录成功',
				// 	icon:'none'
				// })
				// uni.switchTab({
				// 	url: '/pages/home/index'
				// })
				uni.showLoading({
					title:'登录中'
				})
				Login(this.loginForm).then(res => {
					console.log(res,'res');
					if(res.code == 200) {
						uni.setStorageSync('userInfo', {...res.data, username:this.loginForm.username})
						setStorageSync('satoken',res.data.accessToken)
						uni.switchTab({
							url: '/pages/home/index'
						})
						uni.showToast({
							title:'登录成功',
							icon:'none'
						})
					}else {
						uni.showToast({
							title:res.msg,
							icon:'none'
						})
					}
					
				}).catch(err => {
					uni.hideLoading()
				})
				
			},
			goIdentify(){
				uni.navigateTo({
					url: '/pages/my/identify'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		height: 100%;
		overflow: hidden;
		font-family: PingFang SC, PingFang SC;
		  background: linear-gradient(to bottom, #f0fff2, #ffffff);
	}
	.head-bg {
		height: 20vh;
	}
	.login-container {
		box-sizing: border-box;
		// width: 375px;
		background-color: unset;
		height: 812px;
		display: flex;
		flex-direction: column;
		align-items: center;
		.title {
			width: 295px;
			height: 24px;

			font-weight: 600;
			font-size: 24px;
			color: #00B23C;
			line-height: 24px;
			text-align: left;
			font-style: normal;
			text-transform: none;
		}

		.login-form {
			background-color: #fff;
			box-sizing: border-box;
			padding: 5px 20px;
			margin-top: 89px;
			width: 295px;
			height: 110px;
			box-shadow: 0rpx 0rpx 32rpx 0rpx rgba(0,0,0,0.03);
			border-radius: 8px;

			.username,
			.password {
				position: relative;
				height: 50px;
				display: flex;
				align-items: center;
				.eye-open {
					position: absolute;
					right: 0px;
					width: 32px;
					height: 32px;
				}
			}

			.username {
				border-bottom: 1px solid #DCDDDE;
			}

		}

		.login-btn {
			margin-top: 20px;
			display: flex;
			justify-content: center;
			align-items: center;
			width: 295px;
			height: 45px;
			background: #00B23C;
			border-radius: 8px;
			font-weight: 500;
			font-size: 16px;
			color: #FFFFFF;
		}
		.identify{
			position: absolute;
			bottom: 80rpx;
			color: #00B23C;
			text-decoration: underline;
		}
	}
</style>